﻿using BCCommon;
using BCDto.Common.ErrorMessage;
using BCDto.TMS.SpecificServiceType;
using BCDto.TMS.TransferStation;
using BCDto.TMS.TransportSpecificServiceConfig;
using BCDto.TMS.TransportSpecificServiceConfigOverWrite;
using BCEntity.TMS.SpecificServiceType;
using BCEntity.TMS.TransportSpecificServiceConfig;
using BCEntity.TMS.TransportSpecificServiceConfigOverWrite;
using BCService.TMS.Agent.AgentAreaRecord;
using BCService.TMS.SpecificServiceType;
using BCService.TMS.TransferStation;
using BCService.TMS.TransportSpecificServiceConfig;
using BCService.TMS.TransportSpecificServiceConfigOverWrite;
using BCTMSRESTful.Configs;
using BCTMSRESTful.Controllers.Management;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace BCTMSRESTful.Controllers.ClientApp.TransportSpecificServiceConfig
{
    /// <summary>
    /// 运输特殊服务费配置接口
    /// </summary> 
    [Route("api/v1/ClientApp/[controller]")]
    [ApiExplorerSettings(GroupName = "ClientApp")]
    public class TransportSpecificServiceConfigController : ClientAppBaseController
    {
        #region var 
        private ITransportSpecificServiceConfigOverWriteService transportSpecificServiceConfigOverWriteService;
        #endregion


        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary> 
        public TransportSpecificServiceConfigController(ITransportSpecificServiceConfigOverWriteService transportSpecificServiceConfigOverWriteService)
        {
            this.transportSpecificServiceConfigOverWriteService = transportSpecificServiceConfigOverWriteService;
        }
        #endregion
          

        #region Query 
        /// <summary>
        /// 查询运输特殊服务费配置
        /// </summary>
        /// <param name="serviceTitle">特殊服务标题</param>
        /// <param name="specificServiceType">特殊服务类型</param>
        ///<param name="vehicleTypeId">车辆类型Id</param>
        /// <param name="countyCode">区/县代码</param>  
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<TransportSpecificServiceConfigViewDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "specific_service_type")] string specificServiceType,
            [FromQuery(Name = "service_title")] string serviceTitle,
            [FromQuery(Name ="vehicle_type_id")]int? vehicleTypeId,
            [FromQuery(Name = "county_code")] string countyCode)
        {
            if(string.IsNullOrWhiteSpace( countyCode))
            {
                var a = Ok(transportSpecificServiceConfigOverWriteService.GetOnlyListBase(vehicleTypeId, specificServiceType, serviceTitle));
                return a;
            }
            var agentId = GetAgentRecordIdByCountyCode(countyCode);
            if (agentId.HasValue)
            {
                var a  = transportSpecificServiceConfigOverWriteService.GetOnlyList(agentId.Value,vehicleTypeId, specificServiceType, serviceTitle, countyCode);
                if (a == null || a.Count <= 0 )
                {
                    if(string.IsNullOrWhiteSpace(null)  && string.IsNullOrWhiteSpace(null))
                    {
                        return Ok(transportSpecificServiceConfigOverWriteService.GetOnlyListBase(vehicleTypeId, specificServiceType, serviceTitle)); 
                    } 
                }
                return Ok(a);
            }
            else
            {
                var a = Ok(transportSpecificServiceConfigOverWriteService.GetOnlyListBase(vehicleTypeId, specificServiceType, serviceTitle));
                return a;
            }
        }
        #endregion
    }
}